/* 1Kb JavaScript Calendar
 * Author: David Gonzalez
 * License: LGPL
 * Version: 1.1
 * Release: 2010-09-04
 */ 
function calendar(id, m, y)
{
	var A = new Date(y, m - 1, 1),
		SD = 1,	//first day of the week [0-6]
		M = ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'],
		D = ['D', 'L', 'M', 'X', 'J', 'V', 'S'],
		S = [31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
		B = (7 - SD + A.getDay()) % 7,
		h = new Date(), t,
		to = (y == h.getFullYear() && m == h.getMonth() + 1) ? h.getDate() : 50;
	S[1] = (((A.getFullYear() % 100 != 0) && (A.getFullYear() % 4 == 0)) || (A.getFullYear() % 400 == 0)) ? 29 : 28;

	t = '<table class="calendar" cellpadding=0 border=0 cellspacing=0><tr><td class="btn" onClick="calendar(\''+id+'\','+ (m<2?12:m-1) +','+ (m<2?y-1:y) +');">&laquo;</td><td colspan="5" class="title">' + M[m - 1] + ' ' + y + '</td><td class="btn" onClick="calendar(\''+id+'\','+ (m>11?1:m+1) +','+ (m>11?y+1:y) +');">&raquo;</td></tr><tr class="daynames">';
	for (i = 0; i < 7; i++) t += "<td>" + D[(i + SD) % 7] + "</td>";
	t += "</tr><tr>";

	for (i = 1; i < 43; i++)
	{
		var j = i - B,
			x = j > 0 && j <= S[m - 1] ? j : '';
		if (x == to) x = '<b class="today">' + x + '</b>';
		t += '<td>' + x + '</td>';
		if (i % 7 == 0 && i < 36) t += '</tr><tr>';
	}
	document.getElementById(id).innerHTML = t += '</tr>';
}